Skip to content

fix(opencode): flush stdio before cli exit#29340

Closed
YOMXXX wants to merge 1 commit into
anomalyco:devfrom
YOMXXX:fix/cli-flush-stdio-before-exit
Closed

fix(opencode): flush stdio before cli exit#29340
YOMXXX wants to merge 1 commit into
anomalyco:devfrom
YOMXXX:fix/cli-flush-stdio-before-exit

Conversation

@YOMXXX
Copy link
Copy Markdown

@YOMXXX YOMXXX commented May 26, 2026

Issue for this PR

Closes #29330
Closes #26399

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The CLI explicitly calls process.exit() after command handling to avoid hanging subprocesses. Large stdout writes can still be buffered at that point when output is piped, so commands such as opencode export <id> | jq or opencode debug skill | jq can see truncated JSON.

This PR adds a small stdio flush helper and waits for stdout/stderr write callbacks before the final forced exit. The explicit exit behavior is preserved, but pending buffered CLI output gets a chance to drain first.

How did you verify your code works?

  • cd packages/opencode && PATH="$HOME/.bun/bin:$PATH" bun test test/cli/stdout.test.ts
  • cd packages/opencode && PATH="$HOME/.bun/bin:$PATH" bun typecheck
  • git diff --check
  • PATH="$HOME/.bun/bin:$PATH" .husky/pre-push

Screenshots / recordings

Not applicable; CLI stdout flushing only.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PR Found:

The current PR (29340) is a broader fix that addresses the root cause for multiple commands by implementing a general stdio flushing mechanism before CLI exit, whereas PR #26389 may be a more targeted fix for the debug skill command specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode export <id> | jq produces truncated / invalid JSON when piped (large sessions) opencode debug skill returns before output is complete

2 participants